﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Collections;
using System.Windows.Forms;
using System.Data.OleDb;
using MH3GAPP.Dal;
using MH3GAPP.Bll;
using MH3GAPP.Common;
using System.Data;

namespace MH3GAPP.Dal
{
    class MH3GDal:AccessDbCommand
    {

        public int inputDamage(OleDbTransaction trans, int inputID, int damage)
        {
            StringBuilder sbSql = new StringBuilder();
            int result = 0;

            try
            {
                sbSql.Append("UPDATE ").Append(Environment.NewLine);
                sbSql.Append("太刀出招顺序 ").Append(Environment.NewLine);
                sbSql.Append("set damage = " + damage.ToString()).Append(Environment.NewLine);
                sbSql.Append("where ID = " + inputID.ToString()).Append(Environment.NewLine);

                result = ExecuteSqlNonQuery(trans, sbSql.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + sbSql.ToString() + ex.Message);
            }
            return result;
        }

        public int changeDone(OleDbTransaction trans, int inputID, bool isDone)
        {
            StringBuilder sbSql = new StringBuilder();
            int result = 0;

            try
            {
                sbSql.Append("UPDATE DB_Amr SET Done = " + isDone).Append(Environment.NewLine);
                sbSql.Append("where Amr_ID = " + inputID.ToString()).Append(Environment.NewLine);

                result = ExecuteSqlNonQuery(trans, sbSql.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + sbSql.ToString() + ex.Message);
            }
            return result;
        }


        public DataTable getArmDisplayDate(
            OleDbTransaction trans,
            string serchStr,
            bool b1,//头
            bool b2,//胸
            bool b3,//手
            bool b4,//腰
            bool b5,//脚
            bool b6,//男
            bool b7,//女
            bool b8,//近
            bool b9,//远
            int amrRare)//装备等级
        {
            StringBuilder sbSql = new StringBuilder();
            DataTable dt = new DataTable();

            try
            {
                sbSql.Append("select ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Amr_ID, ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Done, ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Amr_Part, ").Append(Environment.NewLine);
                sbSql.Append("ID_Amr_Name.Amr_Name_1, ").Append(Environment.NewLine);
                sbSql.Append("ID_Amr_Name.Amr_Name_3, ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Amr_BG, ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Amr_MF, ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Amr_Rare, ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Amr_Slot, ").Append(Environment.NewLine);
                //sbSql.Append("DB_Amr.Def, ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Def_Max ").Append(Environment.NewLine);
//                 sbSql.Append("DB_Amr.Price ").Append(Environment.NewLine);
//                 sbSql.Append("DB_Amr.Res_Fire, ").Append(Environment.NewLine);
//                 sbSql.Append("DB_Amr.Res_Water, ").Append(Environment.NewLine);
//                 sbSql.Append("DB_Amr.Res_Ice, ").Append(Environment.NewLine);
//                 sbSql.Append("DB_Amr.Res_Thunder, ").Append(Environment.NewLine);
//                 sbSql.Append("DB_Amr.Res_Dragon ").Append(Environment.NewLine);
                sbSql.Append("from DB_Amr, ID_Amr_Name where ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Amr_ID = ID_Amr_Name.Amr_ID ").Append(Environment.NewLine);
                if (!b1)
                {
                    sbSql.Append("AND DB_Amr.Amr_Part <> 1 ").Append(Environment.NewLine);
                }
                if (!b2)
                {
                    sbSql.Append("AND DB_Amr.Amr_Part <> 2 ").Append(Environment.NewLine);
                }
                if (!b3)
                {
                    sbSql.Append("AND DB_Amr.Amr_Part <> 3 ").Append(Environment.NewLine);
                }
                if (!b4)
                {
                    sbSql.Append("AND DB_Amr.Amr_Part <> 4 ").Append(Environment.NewLine);
                }
                if (!b5)
                {
                    sbSql.Append("AND DB_Amr.Amr_Part <> 5 ").Append(Environment.NewLine);
                }
                if (!b6)
                {
                    sbSql.Append("AND DB_Amr.Amr_MF <> 1 ").Append(Environment.NewLine);
                }
                if (!b7)
                {
                    sbSql.Append("AND DB_Amr.Amr_MF <> 2 ").Append(Environment.NewLine);
                }
                if (!b8)
                {
                    sbSql.Append("AND DB_Amr.Amr_BG <> 1 ").Append(Environment.NewLine);
                }
                if (!b9)
                {
                    sbSql.Append("AND DB_Amr.Amr_BG <> 2 ").Append(Environment.NewLine);
                }
                if (amrRare != 0)
                {
                    sbSql.Append("AND DB_Amr.Amr_Rare = " + amrRare.ToString()).Append(Environment.NewLine);
                }
                if (!string.IsNullOrEmpty(serchStr))
                {
                    sbSql.Append("AND (InStr(1, ID_Amr_Name.Amr_Name_1, '" + serchStr + "' , 0)").Append(Environment.NewLine);
                    sbSql.Append("or InStr(1, ID_Amr_Name.Amr_Name_3, '" + serchStr + "', 0))").Append(Environment.NewLine);
                }
                dt = ExecuteSqlDataTable(trans, sbSql.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + sbSql.ToString() + ex.Message);
            }
            return dt;
        }

        public DataTable getArmPartIDForSearch(OleDbTransaction trans, int partID, int bg, int mf)
        {
            StringBuilder sbSql = new StringBuilder();
            DataTable dt = new DataTable();

            try
            {
                sbSql.Append("select ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Amr_ID, ").Append(Environment.NewLine);
                sbSql.Append("ID_Amr_Name.Amr_Name_1, ").Append(Environment.NewLine);
                sbSql.Append("ID_Amr_Name.Amr_Name_3, ").Append(Environment.NewLine);
                sbSql.Append("DB_Amr.Amr_Slot ").Append(Environment.NewLine);
                sbSql.Append("from DB_Amr, ID_Amr_Name ").Append(Environment.NewLine);
                sbSql.Append("where DB_Amr.Amr_ID = ID_Amr_Name.Amr_ID ").Append(Environment.NewLine);
                sbSql.Append("and (DB_Amr.Amr_BG = 3 or DB_Amr.Amr_BG = " + bg +") ").Append(Environment.NewLine);
                sbSql.Append("and (DB_Amr.Amr_MF = 3 or DB_Amr.Amr_BG = " + mf + ") ").Append(Environment.NewLine);

                dt = ExecuteSqlDataTable(trans, sbSql.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + sbSql.ToString() + ex.Message);
            }
            return dt;
        }




    }
}
